package gang.org.springframework.framework.event;

import gang.org.springframework.framework.context.GangApplicationListener;
import gang.org.springframework.framework.factory.GangBeanFactory;
import gang.org.springframework.framework.factory.GangBeanFactoryAware;
import gang.org.springframework.framework.factory.GangConfigurableBeanFactory;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author gang.chen
 * @description
 * @Date 2021/9/1 8:45
 */
public abstract class GangAbstractApplicationEventMulticaster implements GangApplicationEventMulticaster, GangBeanFactoryAware {

    private ClassLoader beanClassLoader;

    private GangConfigurableBeanFactory beanFactory;

    private final GangDefaultListenerRetriever defaultRetriever = new GangDefaultListenerRetriever();

    @Override
    public void setBeanFactory(GangBeanFactory beanFactory) {
        //TODO
    }

    @Override
    public void addApplicationListener(GangApplicationListener<?> listener) {
        this.defaultRetriever.applicationListeners.add(listener);
    }

    @Override
    public void addApplicationListenerBean(String listenerBeanName) {
        synchronized(this.defaultRetriever){
            this.defaultRetriever.applicationListenerBeans.add(listenerBeanName);
            //TODO
            //retrieverCache clear
        }
    }

    /**
     * 业务意义
     * 1）辅助类存储监听器类 retriever 猎狗（Retriever）
     * */
    private class GangDefaultListenerRetriever{

        public final Set<GangApplicationListener<?>> applicationListeners = new LinkedHashSet<>();

        public final Set<String> applicationListenerBeans = new LinkedHashSet<>();

    }
}
